<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>解构赋值</title>
</head>
<body>
<script>

    //交换两个值
    let x = 1;
    let y = 2;
    [x,y] = [y,x];
    console.log("x= "+x," y=" + y);

    //从函数返回多个值
    // 返回一个数组
    function example() {
        return [1, 2, 3];
    }
    let [a, b, c] = example();

    // 返回一个对象
    function example2() {
        return {
            foo: 1,
            bar: 2
        };
    }
    let { foo, bar } = example2();

    //提取JSON数据
    let jsonData = {
        id: 42,
        status: "OK",
        data: [867, 5309]
    };
    let { id, status, data: number } = jsonData;
    console.log(id, status, number);

    //遍历map
    const map = new Map();
    map.set('first', 'hello');
    map.set('second', 'world');

    for (let [key, value] of map) {
        console.log(key + " is " + value);
    }

//    const {a} = {a:1}
//    console.log(a)

    const { aaa, bbb } = { aaa: "aaa", bbb: "bbb" };
    console.log(aaa)

</script>
</body>
</html>